fpath = 'D:\\PythonProject\\T1\\p0\\fun.py'

with open(fpath, 'r+',encoding= 'utf-8' ) as f:
    s = f.read()
    print(s)
    # f.write("author:tangdekun")

import datetime
from io import StringIO

f = StringIO()

f.write("hello")
f.write(" ")
f.write("python")


print(f.getvalue())
s = f.readline()
print(s.strip())
f= StringIO('Hello!\nHi!\nGoodbye!')
while True:
  s = f.readline()
  if s == '':
        break
  print(s.strip())
f.close()


from io import BytesIO

f = BytesIO()
f.write("hello pthon".encode())
s = f.getvalue()
print(s)

import os

print(os.name)
print(os.environ.get('Path').split(";"))
print(os.path.abspath("."))
p2 = os.path.join('D:\\PythonProject\\T1', 'testdir')
if os.path.exists(p2):
    try:
        os.remove(p2)
    except PermissionError as e:
        print(f"erroe:{e}")
else:
    os.mkdir(p2)

print(os.listdir())

import datetime 

def dirl(path):
    result = os.listdir(path)

    for  f in result:
        try:
            fpath = os.path.join(path,f)
            mtime = os.path.getmtime(fpath)
            timef = datetime.datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S')
            size =  os.path.getsize(fpath)
            isDirectory =  os.path.isdir(fpath)
            if isDirectory:
                dictFlag = '<Directory>'
            else :
                dictFlag = '<File>'
            print(f"{timef}  \t {size} \t{dictFlag} \t{f}")
        except FileNotFoundError as e :
            print(f"error:{e}")
dirl("E:\\")

import pickle

d = dict(name="Tom",age =15, height = 180.0)

bytes = pickle.dumps(d)

print(bytes)
currentPath = os.path.abspath(__file__)
fpath = os.path.join(currentPath,"..\demp.txt")
with open(fpath, 'wb') as f:
    pickle.dump(d, f)
f.close()

with open(fpath, "rb") as f:
   d1 = pickle.load(f)
   print(d1)
   f.close()

import json
data = {'name':'tangdekun','age':15,'height':180.0}
with open('a.json','w+',encoding="utf-8")  as f:
    json.dump(data,f)
    f.close()


with open('a.json','r',encoding="utf-8")  as f:
    data1= json.load(f)
    print(data1)
    f.close()


import csv

cdata = [['name','age','height'],['Tom',15,180.0]]
with open('b.csv','w',newline='') as f:
    writer = csv.writer(f,delimiter=',')
    writer.writerows(cdata)
    f.close()

with open('b.csv','r') as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)
    f.close()